﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace Pilhas
{
    public enum ButtonClicked
    {
        Create,
        Destroy,
        Pop,
        Push
    }

    public class Buttons : CommomFunctions.Buttons
    {
        /// <summary>
        /// Creates a new empty stack.
        /// The creation of the stack consists in setting the elements to visible.
        /// It will also reset all the counters and update the trace information.
        /// </summary>
        /// <param name="btns">
        /// Buttons that will be enabled/disabled. 
        /// The button responsible for creating new stacks (btns[0]) will be disabled. 
        /// After the first stack is created a new one will be created only after the destruction of the existent one.
        /// </param>
        /// <param name="stackBorder">
        /// Represents the border of the stack. It symbolizes a container for the ellipses that will be the elements.
        /// </param>
        public static void btnCreate_Click(Button[] btns, Rectangle stackBorder)
        {
            habilitaBotoes(btns);
            btns[0].IsEnabled = false;

            stackBorder.Visibility = Visibility.Visible;

            ControlVariables.setElementsVisibility(ButtonClicked.Create);
            ControlVariables.resetCounters();
            ControlVariables.writeToTrace(ButtonClicked.Create);
        }

        /// <summary>
        /// Destroies the existent stack.
        /// The destruction of the stack consists in setting the elements to hidden.
        /// It will also reset all the counters and update the trace information.        
        /// </summary>
        /// <param name="btns">
        /// Buttons that will be enabled/disabled. 
        /// The button responsible for creating new stacks (btns[0]) will be enabled. 
        /// After the destruction of the existent stack a new one needs to be created.
        ///</param>
        /// <param name="stackBorder">
        /// Represents the border of the stack. It symbolizes a container for the ellipses that will be the elements.
        /// </param>
        public static void btnDestroy_Click(Button[] btns, Rectangle stackBorder)
        {
            desabilitaBotoes(btns);
            btns[0].IsEnabled = true;

            stackBorder.Visibility = Visibility.Hidden;

            ControlVariables.setElementsVisibility(ButtonClicked.Destroy);
            ControlVariables.resetCounters();
            ControlVariables.writeToTrace(ButtonClicked.Destroy);
        }

        /// <summary>
        /// Pops an element from the stack. 
        /// </summary>
        public static void btnPop_Click()
        {
            if (ControlVariables.testUnderflow())
                return;

            ControlVariables.updatemyStack(ButtonClicked.Pop);
            ControlVariables.setElementsVisibility(ButtonClicked.Pop);
            ControlVariables.writeToTrace(ButtonClicked.Pop);
        }

        /// <summary>
        /// Pushes an element to the stack.
        /// The content of the element can be an automatic number or a label informed by the user
        /// </summary>
        public static void btnPush_Click()
        {
            if (ControlVariables.testOverflow())
                return;

            ControlVariables.updatemyStack(ButtonClicked.Push);
            
            if(!ControlVariables.setLabelsContent())
                return;
            
            ControlVariables.setElementsVisibility(ButtonClicked.Push);
            ControlVariables.updateImageMargin();
            ControlVariables.writeToTrace(ButtonClicked.Push);
        }

    }
}
